package com.sgb.kjwl.view.ui.adapter.pick;

import android.content.Context;
import android.text.Html;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.pick.PickSearchResult;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class PickSearchResultAdapter extends BaseRecycleAdapter<PickSearchResult> {

    private TextView tvName;
    private String text = "";

    public PickSearchResultAdapter(Context context, List<PickSearchResult> datas) {
        super(context, R.layout.item_pick_search_result, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final PickSearchResult entity) {
        holder.setBinding(BR.viewModel, entity);
        tvName = holder.getItem().findViewById(R.id.name);
        if (text != null) {
            String temp = entity.getTitle().replace(text, "<font color='#EF4033'>" + text + "</font>");
            tvName.setText(Html.fromHtml(temp));
        }
    }

    public void setSelectedText(String text) {
        this.text = text;
    }
}
